package com.example.demo003argsresolver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

// 注册进Spring组件内
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    ApplicationContext applicationContext;
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        CurrUserArgumentResolver currUserArgumentResolver = new CurrUserArgumentResolver();
        TranUserArgumentResolver tranUserArgumentResolver = new TranUserArgumentResolver();
        // 利用工厂给容器外的对象注入所需组件
        applicationContext.getAutowireCapableBeanFactory().autowireBean(currUserArgumentResolver);
        resolvers.add(currUserArgumentResolver);
        resolvers.add(tranUserArgumentResolver);
    }
}
